using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Diagnostics;

namespace WindowsApplication1
{
    public partial class breakForm : Form
    {
        [DllImport("user32.dll", EntryPoint = "SystemParametersInfo", SetLastError = true)]
        public static extern bool SystemParametersInfo(uint action, uint param, uint vparam, uint init);
        public breakForm()
        {
            InitializeComponent();
        }

        private Form1 pForm;

        public void setPForm(Form1 form)
        {
            pForm = form;
        }

        private int seconds;
        private int secondsPassed = 0;

        internal void DoIt(int seconds)
        {

            label1.Location = new System.Drawing.Point(12, this.Size.Height / 2 - label1.Size.Height / 2);
            //progressBar1.Maximum = seconds;
            //progressBar1.Value = 0;
            secondsPassed = 0;
            panel.Size = new Size(0,20);
            iTunesButton.Hide();
            foreach (Process process in Process.GetProcesses())
            {
                if (process.MainWindowTitle == "iTunes")
                {
                    iTunesButton.Show();
                    break;
                }
            }
            Show();
            BringToFront();
            Focus();
            SystemParametersInfo(97,1,0,0);
            this.seconds = seconds;
            timer1.Start();
            // Check if iTunes is running
        }

        private void breakForm_Load(object sender, EventArgs e)
        {

        }

        private void breakForm_FormClosed(object sender, FormClosedEventArgs e)
        {
            SystemParametersInfo(97, 0, 0, 0);
        }


        private void breakForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (e.CloseReason == CloseReason.UserClosing)
                e.Cancel = true;
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (secondsPassed >= seconds)
            {
                if (seconds < 60)
                {
                    Hide();
                    Close();
                }
                timer1.Stop();
            }
            secondsPassed++;
            //progressBar1.PerformStep();
            panel.Size = new Size((int)Math.Round(((float)secondsPassed/(float)seconds)*400.00),20);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            iTunesLib.iTunesApp it = new iTunesLib.iTunesApp();
            it.Pause();
            iTunesButton.Hide();
        }

        private void breakForm_MouseMove(object sender, MouseEventArgs e)
        {
            if (!timer1.Enabled)
            {
                Hide();
                Close();
                pForm.resetTimers();
            }
        }
    }
}